import { BoxGeometry, Color, Mesh, MeshBasicMaterial, Object3D } from "three";

// 显示区域的最大宽度
const defaultXmax = 2000, defaultYmax = 2000, defaultZmax = 2000;
// 单个模型的长宽高
const defaultWmax = 20, defaultHmax = 20, defaultLmax = 20;


const count = 5000;
interface Param {
  Xmax: number,
  Ymax: number,
  Zmax: number,
  // 单个模型的长宽高
  Wmax: number, Hmax: number, Lmax: number;
}

export function GetRandomObj(params: Partial<Param> = {}) {
  Object.assign(params || {}, {
    Xmax: defaultXmax, Ymax: defaultYmax, Zmax: defaultZmax,
    Wmax: defaultWmax, Hmax: defaultHmax, Lmax: defaultLmax
  })
  const { Xmax, Ymax, Zmax,
    Wmax, Hmax, Lmax } = params as Param
  const Objs: Object3D[] = []
  for (let index = 0; index < count; index++) {
    const box = new BoxGeometry(Wmax * Math.random(), Hmax * Math.random(), Lmax * Math.random());
    const color = new Color()
    color.set(Math.random(), Math.random(), Math.random())
    const material = new MeshBasicMaterial({
      color
    })
    const mesh = new Mesh(box, material);
    mesh.position.set(Xmax * Math.random() - Xmax / 2, Ymax * Math.random() - Ymax / 2, Zmax * Math.random() - Zmax / 2)
    Objs.push(mesh)
  }
  return Objs
}
export const RandomObjs = GetRandomObj()